package com.mssh.entity.pojo;

import lombok.Data;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: 熳殊沙华
 * @Date: 2025/03/25/12:29
 * @Description:
 */
@Data
public class Result<T> {
    private String code;
    private String msg;
    private T result;

    /**
     * 构造函数
     */
    public Result() {
    }

    public Result(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result (String code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.result = data;
    }

    /**
     * 成功报文
     * @return
     */
    public Result<T> success(){
        this.setCode("0000");
        this.setMsg("操作成功");
        return this;
    }

    public Result<T> success(T t){
        this.setCode("0000");
        this.setMsg("操作成功！");
        this.setResult(t);
        return this;
    }

    public Result<T> success(String msg){
        this.setCode("0000");
        this.setMsg(msg);
        return this;
    }

    public Result<T> success(T t, String msg){
        this.setCode("0000");
        this.setMsg(msg);
        this.setResult(t);
        return this;
    }

    /**
     * 失败报文
     * @return
     */
    public Result<T> failed(){
        this.setCode("9999");
        this.setMsg("操作失败！");
        return this;
    }

    public Result<T> failed(T t){
        this.setCode("9999");
        this.setMsg("操作失败！");
        this.setResult(t);
        return this;
    }

    public Result<T> failed(String msg){
        this.setCode("9999");
        this.setMsg(msg);
        return this;
    }

    public Result<T> failed(T t, String msg){
        this.setCode("9999");
        this.setMsg(msg);
        this.setResult(t);
        return this;
    }

    public Result<T> failed(String code, String msg){
        this.setCode(code);
        this.setMsg(msg);
        return this;
    }
}
